package net.andersand.games.yatzy;

/**
 * 
 * @author Anders Sandberg Nordbø
 */
class Player implements Comparable<Player> {

	private static int players = 0;

	private String name;
	private int id;
	private Dice dice;
	private Turn turn;
	private ScoreKeeper scoreKeeper;

	Player(String name) {
		dice = new Dice();
		this.name = name;
		id = ++players;
		turn = new Turn(this);
		scoreKeeper = new ScoreKeeper(id);
	}

	String getName() {
		return name;
	}

	Dice getDice() {
		return dice;
	}

	int getId() {
		return id;
	}

	Turn getTurn() {
		return turn;
	}

	public int compareTo(Player p) {
		return getId() - p.getId();
	}

	public String toString() {
		return getName();
	}

	ScoreKeeper getScoreKeeper() {
		return scoreKeeper;
	}

	boolean addScore(Score score) {
		return getScoreKeeper().addScore(score);
	}

	public int sum() {
		return getScoreKeeper().sum();
	}

	public boolean isDone() {
		return getScoreKeeper().getScore().size() == ScoreType.values().length;
	}

}